<template>
    <view class="container">
        <!-- 页面标题 -->
        <view class="header">
            <view class="header-title">已加入的组织</view>
            <view class="header-subtitle">查看您参与的所有组织</view>
        </view>

        <!-- 加载状态 -->
        <view v-if="loading" class="loading-container">
            <view class="loading-text">加载中...</view>
        </view>

        <!-- 功能暂未开放提示 -->
        <view v-else class="feature-unavailable-container">
            <view class="unavailable-icon">🚧</view>
            <view class="unavailable-title">功能暂未开放</view>
            <view class="unavailable-subtitle">该功能正在开发中，敬请期待！</view>
            <view class="unavailable-desc">
                <text>我们正在努力完善组织管理功能，</text>
                <text>预计将在后续版本中推出。</text>
            </view>
            <view class="unavailable-actions">
                <button class="action-button" @click="goBack">返回</button>
                <button class="action-button primary" @click="refreshPage">刷新</button>
            </view>
        </view>

        <!-- 组织列表 -->
        <view v-else class="organization-list">
            <view 
                v-for="(organization, index) in organizationList" 
                :key="organization.id" 
                class="organization-card"
                @click="goToOrganizationDetail(organization.id)"
            >
                <image :src="organization.logo" mode="aspectFill" class="organization-image"></image>
                <view class="organization-content">
                    <view class="organization-title">{{ organization.name }}</view>
                    <view class="organization-description" v-html="organization.description"></view>
                    <view class="organization-info">
                        <view class="info-item">
                            <text class="info-icon">👥</text>
                            <text class="info-text">{{ organization.memberCount || 0 }} 名成员</text>
                        </view>
                        <view class="info-item">
                            <text class="info-icon">📍</text>
                            <text class="info-text">{{ organization.location }}</text>
                        </view>
                        <view class="info-item">
                            <text class="info-icon">📅</text>
                            <text class="info-text">加入时间：{{ formatDateTime(organization.joinTime) }}</text>
                        </view>
                    </view>
                    <view class="organization-status">
                        <text class="status-text" :class="getStatusClass(organization.status) || 'status-default'">
                            {{ getStatusText(organization.status) }}
                        </text>
                    </view>
                </view>
            </view>
        </view>

        <!-- 底部提示 -->
        <view class="footer-tip">
            <text>点击组织可查看详情</text>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            loading: true,
            organizationList: [],
            userId: null
        };
    },
    onLoad() {
        this.initPage();
    },
    onShow() {
        // 每次显示页面时刷新数据
        if (this.userId) {
            this.loadUserOrganizations();
        }
    },
    methods: {
        // 初始化页面
        initPage() {
            // 检查用户登录状态
            const userData = this.f.storage('user_data');
            if (this.f.isnull(userData) === '') {
                this.f.msg('请先登录');
                this.f.nav('/pages/login/login1');
                return;
            }
            
            this.userId = userData.userId;
            this.loadUserOrganizations();
        },

        // 加载用户已加入的组织
        loadUserOrganizations() {
            this.loading = true;
            // 模拟加载过程，然后显示功能暂未开放提示
            setTimeout(() => {
                this.loading = false;
                // 不加载任何数据，直接显示功能暂未开放提示
            }, 1000);
        },

        // 返回上一页
        goBack() {
            uni.navigateBack({
                delta: 1
            });
        },

        // 刷新页面
        refreshPage() {
            this.loadUserOrganizations();
        }
    }
}
</script>

<style scoped>
.container {
    background-color: #f5f5f5;
    min-height: 100vh;
    padding: 20rpx;
}

/* 页面标题 */
.header {
    text-align: center;
    padding: 40rpx 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: -20rpx -20rpx 30rpx -20rpx;
    color: white;
}

.header-title {
    font-size: 36rpx;
    font-weight: bold;
    margin-bottom: 10rpx;
}

.header-subtitle {
    font-size: 28rpx;
    opacity: 0.9;
}

/* 加载状态 */
.loading-container {
    text-align: center;
    padding: 100rpx 0;
}

.loading-text {
    font-size: 28rpx;
    color: #999;
}

/* 功能暂未开放提示 */
.feature-unavailable-container {
    text-align: center;
    padding: 120rpx 40rpx;
    background: white;
    margin: 20rpx;
    border-radius: 20rpx;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
}

.unavailable-icon {
    font-size: 120rpx;
    margin-bottom: 30rpx;
    opacity: 0.8;
}

.unavailable-title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 15rpx;
}

.unavailable-subtitle {
    font-size: 28rpx;
    color: #666;
    margin-bottom: 20rpx;
}

.unavailable-desc {
    font-size: 24rpx;
    color: #999;
    line-height: 1.6;
    margin-bottom: 40rpx;
}

.unavailable-desc text {
    display: block;
    margin-bottom: 5rpx;
}

.unavailable-actions {
    display: flex;
    gap: 20rpx;
    justify-content: center;
}

.action-button {
    padding: 20rpx 40rpx;
    border-radius: 25rpx;
    font-size: 28rpx;
    border: 2rpx solid #e9ecef;
    background: white;
    color: #666;
    transition: all 0.3s ease;
}

.action-button:active {
    transform: scale(0.95);
}

.action-button.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.action-button.primary:active {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

/* 组织列表 */
.organization-list {
    padding: 20rpx;
}

.organization-card {
    background: white;
    border-radius: 20rpx;
    margin-bottom: 24rpx;
    overflow: hidden;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    position: relative;
}

.organization-card:active {
    transform: translateY(2rpx);
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.12);
}

.organization-image {
    width: 100%;
    height: 320rpx;
    object-fit: cover;
}

.organization-content {
    padding: 24rpx;
}

.organization-title {
    font-size: 36rpx;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 12rpx;
    line-height: 1.3;
}

.organization-description {
    font-size: 28rpx;
    color: #7f8c8d;
    line-height: 1.6;
    margin-bottom: 20rpx;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.organization-info {
    display: flex;
    flex-direction: column;
    gap: 12rpx;
    margin-bottom: 20rpx;
    padding: 16rpx;
    background: #f8f9fa;
    border-radius: 12rpx;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 12rpx;
}

.info-icon {
    font-size: 28rpx;
    margin-right: 8rpx;
}

.info-text {
    font-size: 26rpx;
    color: #495057;
    font-weight: 500;
}

.organization-status {
    display: flex;
    justify-content: flex-end;
    margin-top: 8rpx;
}

.status-text {
    padding: 12rpx 20rpx;
    border-radius: 25rpx;
    font-size: 24rpx;
    font-weight: 600;
    transition: all 0.2s ease;
}

.status-default {
    background: linear-gradient(135deg, #e9ecef, #f8f9fa);
    color: #495057;
    border: 1rpx solid #dee2e6;
}

.status-warning {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    color: #856404;
    border: 1rpx solid #ffd43b;
}

.status-success {
    background: linear-gradient(135deg, #d4edda, #a8e6cf);
    color: #155724;
    border: 1rpx solid #28a745;
}

.status-error {
    background: linear-gradient(135deg, #f8d7da, #ffb3ba);
    color: #721c24;
    border: 1rpx solid #dc3545;
}

/* 底部提示 */
.footer-tip {
    text-align: center;
    padding: 30rpx 0;
    color: #999;
    font-size: 24rpx;
}
</style>
